#pragma once
#include"public_struct.h"
int is_data(vector<vector<int>>& grid, int x, int y) {
	if (x < 0 || x == grid.size())return 1;
	if (y < 0 || y == grid[x].size())return 1;
	return 1 - grid[x][y];
}

int islandPerimeter(vector<vector<int>>& grid) {
	int result = 0;
	for (int i = 0; i < grid.size(); ++i) {
		for (int j = 0; j < grid[i].size(); ++j) {
			if (grid[i][j]) {
				result += is_data(grid, i - 1, j) + is_data(grid, i + 1, j) + is_data(grid, i, j - 1) + is_data(grid, i, j + 1);
			}
		}
	}
	return result;
}